from collections import Counter
from typing import List

class Solution:
    def numRabbits(self, answers: List[int]) -> int:
        c = Counter(answers)
        res = 0
        for ans, cnt in c.items():
            # 当 cnt == ans + 1时， ans+1是最少答案
            # 当 cnt < ans + 1,    ans+1是最少答案
            # 当 cnt > ans + 1,    比如 3,3,3,3,3,3,3,3,3  最少12个
            #   cnt // (ans+1) * (ans+1) + (1+ans)  如果没除尽 3,3,3,3,3,3,3,3,3  最少12个
            #   cnt // (ans+1) * (ans+1)            如果除尽 3,3,3,3,3,3,3,3      最少8个
            if cnt <= ans + 1:
                res += ans + 1
            else:
                # res += cnt // (ans+1) * (ans+1)
                # if cnt % (ans+1) != 0:
                #     res += 1 + ans
                res += (cnt + ans) // (ans+1) * (ans+1)
            # res += (ans+cnt) // (ans + 1) * (ans+1)
        return res

